package com.wyw.demo.controller;

import com.wyw.demo.common.CacheConstant;
import com.wyw.demo.common.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 测试Stream发送消息
 *
 * @Author Mr Wu yewen.wu.china@gmail.com
 * @Date 2023/2/27 15:56
 */
@RestController
@Slf4j
public class ProducerController {

    @Resource
    private RedisUtil redisUtil;

    /**
     * 模拟生产消息
     * @return
     */
    @GetMapping("send")
    public String sendMessage() {
        String redisKey = CacheConstant.REDIS_STEAM_01;
        for(int i = 0; i< 5; i ++) {
            Map<String, String> map = new HashMap();
            map.put("w", "w" + i);
            map.put("y", "y" + i);
            map.put("ww", "ww" + i);
            map.put("time", "t-" +System.currentTimeMillis());
            String result = redisUtil.addMap(redisKey, map);
            log.info("返回结果：{}", result);
        }
        return "success";
    }

    @GetMapping("create")
    public String sendMessage(@RequestParam String groupName, @RequestParam String key) {
        String group = redisUtil.createGroup(key, groupName);
        return group;
    }

}
